var enquiry = {
	currentEnquiryPageNo:0,
    list:function(page){
    	$.ajax({
	        type: "GET",
	        url: "../enquiry/list.json",
	        cache:false,
	        dataType: "json",
			data : {"currentPage":page + 1,"perPageSize":10},
	        success: function(data){
	        	if(data.result == 'success'){
                    $('#enquiryList').html("");
                    
                    $.each(data.enquiryList, function(index, obj) {
                        var html = "<tr><td>"+obj.title+"</td><td>"+obj.companyName+"</td><td>"+obj.contactPerson+"</td><td>"+
                            obj.tel+"</td><td>"+obj.email+"</td><td>"+new Date(obj.createDate).pattern("yyyy-MM-dd HH:mm:ss")+"</td>"+
                            "<td><a href='javascript:enquiry.show("+obj.id+");'>Detail Info</a> | "+
                            "<a href='javascript:enquiry.deleteEnquiry("+obj.id+");'>Delete</a></td></tr>";
                            
                        $('#enquiryList').append(html);
                    });
                    
                    $("#paginationDiv").pagination(data.enquiryListCount, {
                        callback: enquiry.list,//回调函数
                        num_display_entries: 5,
                        num_edge_entries: 3,
                        items_per_page:10,//每页显示多少条
                        current_page:page//当前页码
                    });
                    
                    currentEnquiryPageNo = page;
	        	}else{
                    $.msgBox.alert({
                        title:'Tips',
                        msg:'System error!Please try again later!',
                        icon:'warning',
                        width:350
                    });
                }
	        }
    	});
    },
    deleteEnquiry:function(id){
    	$.msgBox.prompt({
            title:'Tips',
            msg:'Are you sure delete this record?',
            icon:'warning',
            width:350,
            yesFun:function(){
                $.ajax({
        	        type: "POST",
        	        url: "../enquiry/delete.json",
        	        cache:false,
        	        dataType: "json",
        			data : {"id":id},
        	        success: function(data){
        	        	if(data.result == "success"){
        	        		enquiry.list(currentEnquiryPageNo);
        	        	}else{
                            $.msgBox.alert({
                                title:'Tips',
                                msg:'System error!Please try again later!',
                                icon:'warning',
                                width:350
                            });
        	        	}
        	        }
        	   });
            }
    	});
    },
    show:function(id){
        $.ajax({
            type: "GET",
            url: "../enquiry/"+id+".json",
            cache:false,
            dataType: "json",
            success: function(data){
                if(data.result == 'success'){
                    var enquiryObj = data.enquiry;
                    var html = "<ul class='mode_add enquiry_info pad10 clearfix'>"+
                        "<li><label>Title:</label><div class='enquiry_infoCnt'>"+enquiryObj.title+"</div></li>"+
                        "<li class='clearfix'><label>Contents:</label><div class='enquiry_infoCnt'>"+enquiryObj.content+"</div></li>"+
                        "<li><label>Company Name:</label><div class='enquiry_infoCnt'>"+enquiryObj.companyName+"</div></li>"+
                        "<li><label>Company Add:</label><div class='enquiry_infoCnt'>"+enquiryObj.companyAdd+"</div></li>"+
                        "<li><label>Postcode:</label><div class='enquiry_infoCnt'>"+enquiryObj.postcode+"</div></li>"+
                        "<li><label>Contact person:</label><div class='enquiry_infoCnt'>"+enquiryObj.contactPerson+"</div></li>"+
                        "<li><label>Tel:</label><div class='enquiry_infoCnt'>"+enquiryObj.tel+"</div></li>"+
                        "<li><label>E-mail:</label><div class='enquiry_infoCnt'>"+enquiryObj.email+"</div></li>"+
                        "<li><label>website:</label><div class='enquiry_infoCnt'>"+enquiryObj.website+"</div></li>"+
                        "<li><label>Fax:</label><div class='enquiry_infoCnt'>"+enquiryObj.fax+"</div></li>"+
                    "</ul>";
                	$.msgBox.alert({
                        title:'Enquiry',
                        html:html,
                        width:600
                    });
                }else{
                    $.msgBox.alert({
                        title:'Tips',
                        msg:'System error!Please try again later!',
                        icon:'warning',
                        width:350
                    });
                }
            }
        });
    }
};